/*
 *	This file is part of Lounge-Cast.
 *
 *  Author:  	Markus Moormann
 *	E-mail:  	mmoorman@uni-osnabrueck.de
 *	Copyright:	University of Osnabrueck (Zentrum Virtuos)
 * 	Website:	www.uni-osnabrueck.de
 *	Date:		16.02.2011
 *
 *	Lounge-Cast is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *	Lounge-Cast is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Lounge-Cast.  If not, see <http://www.gnu.org/licenses/>.
 */
package multimedia.view.renderer
{
	import multimedia.control.event.feed.UpdateFeedEvent;
	import multimedia.model.vo.FeedVO;
	
	import mx.controls.ColorPicker;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.events.ColorPickerEvent;
	import mx.events.FlexEvent;
	import mx.events.ListEvent;
	
	public class BackgroundColorSelectorRenderer extends ColorPicker implements IListItemRenderer
	{
		
		private var _data:Object;
		
		public function BackgroundColorSelectorRenderer()
		{
			super();
			addEventListener(FlexEvent.DATA_CHANGE, onDataChange);
			//addEventListener(ListEvent.CHANGE, onSelectionChange);
			addEventListener(ColorPickerEvent.CHANGE, onSelectionChange);
		}
		
		public function set data(data:Object):void
		{
			_data = data;
			if(data is FeedVO)
			{
				this.selectedColor = (data as FeedVO).background_color;
			}
		}
		
		public function get data():Object
		{
			return _data;
		}
		
		private function onDataChange(event:FlexEvent):void
		{
			
		}
		
		private function onSelectionChange(event:ColorPickerEvent):void
		{
			//trace(event.color);
			var feed:FeedVO = data as FeedVO;
			feed.background_color = event.color;
			this.selectedColor = event.color;
			new UpdateFeedEvent(feed).dispatch();
			//trace(event.color);
		}
	}
}